package ygg.exporter.swf.tag
{
	import j.sus2maj7.encoding.*;
	import j.sus2maj7.context.*;
	import j.sus2maj7.util.*;
	
	import flash.filesystem.*;
	import flash.utils.*;
	
	import ygg.exporter.swf.*;
	
	import ygg.encoding.swf.tag.*;
	import ygg.encoding.swf.tag.object.*;
	import ygg.encoding.swf.structure.*;
	import ygg.encoding.swf.abc.*;
	import ygg.encoding.swf.abc.object.*;
	
	public class DefineBitsJPEG3Exporter extends TagExporter
	{
		public function DefineBitsJPEG3Exporter()
		{
			super();
		}
		
		override public function export(o:*, context:IContext = null):void
		{
			var i:DefineBitsJPEG3 = o as DefineBitsJPEG3;
			trace('DefineBitsJPEG3Exporter', i.characterId, i.alphaDataOffset, i.imageData.length, i.bitmapAlphaData.length);
			
			var ba:ByteArray = new ByteArray();
			i.imageData.position = 0;
			TagBinary(i.imageData).syncBits();
			
			var j:uint = i.imageData.readUnsignedInt();
			
			var type:uint = 0;
			//trace( ByteUtil.print(i.imageData.ba) );
			trace(j.toString(16) );
			if (j == 0x89504e47)
			{
				j = i.imageData.readUnsignedInt();
				
				if (j == 0x0d0a1a0a)
				{
					type = 1;
				}
			}
			else if (j == 0x47494638)
			{
				j = i.imageData.readUnsignedShort();
				if (j == 0x3961)
				{
					type = 2;
				}
			}
			i.imageData.position = 0;
			trace(type);
			
			switch (type)
			{
				case 0:
					writeBytesToFile(i.imageData.ba, context.vars.imageDir.resolvePath ('jpeg3_' + i.characterId + '_' + type + '.jpg') );
					break;
				case 1:
					break;
				case 2:
				default:
					break;
			}
			
			
		}
	}
}